<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02 倒计时</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul li {
            list-style: none;
        }
        
        input[type="button"] {
            margin: 50px;
        }
    </style>
</head>

<body>
    <input type="button" style="height: 32px;width: 180px;" value="点击发送验证码" onclick="sendCode(this)">


    <script>
        var clock = '';
        var nums = 10;
        var btn;

        function sendCode(thisBtn) {
            // console.log('thisBtn:', thisBtn);
            btn = thisBtn;
            btn.disabled = true;
            console.log('000');

            btn.value = nums + '秒后可以重新获取';
            clock = setInterval(doLoop, 1000); //每一秒  都执行一次这个  doLoop方法
        }

        function doLoop() {
            nums--;
            if (nums > 0) {
                btn.value = nums + '秒后可以重新获取';
            } else {
                clearInterval(clock);
                btn.disabled = false;
                btn.value = '点击发送验证码';
                nums = 10;
            }
        }
    </script>
</body>

</html>